<?php

namespace App\Services;

use App\Dao\BaseDao;
use App\Exceptions\SysExceptions;
use Mrgoon\AliSms\AliSms;

class SmsServices
{

    static $priMsgKey='phone_';

    public static function checkVerCode($code,$phone)
    {
            if(env('APP_DEBUG_LOCAL')){
                if($code == 666666 || $code == '666666'){
                    return true;
                }
            }

            if(Cache::getCacheValue(self::$priMsgKey.$phone) != $code){
                throw new SysExceptions('验证码不正确');
            }
    }

    /**
     * @throws SysExceptions
     */
    public static function send($params)
    {
        if(env('APP_DEBUG_LOCAL')){
            Cache::setCache(self::$priMsgKey.$params['phone'],666666);
            return;
        }
        $random = rand(111111,999999);
        $result = (new AliSms())->sendSms($params['phone'],'SMS_305011863',[
            'code'=>"$random"
        ],[
            'access_key'=>'LTAI5t8Hpm68EQHwa7AE9Nu4',
            'access_secret'=>'KDjgFsZcYUVWSd3MAjPtHFEeIf7Pr2',
            'sign_name'=>'魏民'
        ]);
        if($result->Code == 'OK'){
            Cache::setCache(self::$priMsgKey.$params['phone'],$random);
        }else{
            BaseDao::error('发送失败:'.$result->Message);
        }

    }

    public static function sendNotice($money,$phone){

        $result = (new AliSms())->sendSms($phone,'SMS_468875511',[
            'code'=>"$money"
        ],[
            'access_key'=>'LTAI5tDNM9Pdf7uF7XmsDBeW',
            'access_secret'=>'FfftMaPoZ2RVmlUrDqdwS6kxlMwIWa',
            'sign_name'=>'济南铭宇网络科技'
        ]);
        if($result->Code != 'OK'){
            BaseDao::error('发送失败:'.$result->Message);

        }
    }
}
